package com.qf.demo;

import com.qf.config.SpringConfig;
import com.qf.pojo.Account;
import com.qf.service.AccountService;
import org.apache.commons.dbutils.QueryRunner;
import org.junit.jupiter.api.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.util.List;

/**
 * @ClassName TestAccount
 * @Description TODO
 * @Author 86181
 * @Date 2022/8/30 14:47
 * @Version 1.0
 **/
public class TestAccount {
@Test
    public void test(){
        //1.获取容器
//        ApplicationContext ac = new ClassPathXmlApplicationContext("bean.xml");
    AnnotationConfigApplicationContext ac = new AnnotationConfigApplicationContext(SpringConfig.class);
        //2.得到业务层对象
        AccountService as = ac.getBean("accountService", AccountService.class);
        //3.执行方法
        List<Account> accounts = as.findAllAccount();
        for (Account account : accounts) {
            System.out.println(account);
        }
    /**
     * 输出结果我true 说明QueryRunner是单列的
     */
    QueryRunner runner1 = ac.getBean("runner", QueryRunner.class);
    QueryRunner runner2 = ac.getBean("runner",QueryRunner.class);
    System.out.println(runner1==runner2);
}


}
